/* Inicializando Variáveis */
var oTable;
var oTableB;
var andamentoTabela;
var tabCopy = $(".boxTabela").html();

/* API method to get paging information */
$.fn.dataTableExt.oApi.fnPagingInfo = function(oSettings) {
	return {
		"iStart": oSettings._iDisplayStart,
		"iEnd": oSettings.fnDisplayEnd(),
		"iLength": oSettings._iDisplayLength,
		"iTotal": oSettings.fnRecordsTotal(),
		"iFilteredTotal": oSettings.fnRecordsDisplay(),
		"iPage": oSettings._iDisplayLength === -1 ?
		0 : Math.ceil(oSettings._iDisplayStart / oSettings._iDisplayLength),
		"iTotalPages": oSettings._iDisplayLength === -1 ?
		0 : Math.ceil(oSettings.fnRecordsDisplay() / oSettings._iDisplayLength)
	};
}

/* Bootstrap style pagination control */
$.extend($.fn.dataTableExt.oPagination,{
	"bootstrap": {
		"fnInit": function(oSettings, nPaging, fnDraw) {
			var oLang = oSettings.oLanguage.oPaginate;
			var fnClickHandler = function(e) {
				e.preventDefault();
				if (oSettings.oApi._fnPageChange(oSettings, e.data.action)) {
					fnDraw(oSettings);
				}
			};

			$(nPaging).append(
			'<ul class="pagination">' +
			'<li class="first disabled"><a href="#">' + oLang.sFirst + '</a></li>' +
			'<li class="prev  disabled"><a href="#">' + oLang.sPrevious + '</a></li>' +
			'<li class="next  disabled"><a href="#">' + oLang.sNext + '</a></li>' +
			'<li class="last  disabled"><a href="#">' + oLang.sLast + '</a></li>' +
			'</ul>');
			var els = $('a', nPaging);
			$(els[0]).bind('click.DT', {
				action: "first"
			}, fnClickHandler);
			$(els[1]).bind('click.DT', {
				action: "previous"
			}, fnClickHandler);
			$(els[2]).bind('click.DT', {
				action: "next"
			}, fnClickHandler);
			$(els[3]).bind('click.DT', {
				action: "last"
			}, fnClickHandler);
		},

		"fnUpdate": function(oSettings, fnDraw) {
			var iListLength = 5;
			var oPaging = oSettings.oInstance.fnPagingInfo();
			var an = oSettings.aanFeatures.p;
			var i, j, sClass, iStart, iEnd, iHalf = Math.floor(iListLength / 2);

			if (oPaging.iTotalPages < iListLength) {
				iStart = 1;
				iEnd = oPaging.iTotalPages;
			} else if (oPaging.iPage <= iHalf) {
				iStart = 1;
				iEnd = iListLength;
			} else if (oPaging.iPage >= (oPaging.iTotalPages - iHalf)) {
				iStart = oPaging.iTotalPages - iListLength + 1;
				iEnd = oPaging.iTotalPages;
			} else {
				iStart = oPaging.iPage - iHalf + 1;
				iEnd = iStart + iListLength - 1;
			}

			for (i = 0, iLen = an.length; i < iLen; i++) {
				// Remove the middle elements
				$('li:gt(1)', an[i]).filter(':not(.next,.last)').remove();

				// Add the new list items and their event handlers
				for (j = iStart; j <= iEnd; j++) {
					var act = "";
					if (j == oPaging.iPage + 1) {
						act = 'class="active"';
					}
					$('<li ' + act + '<a href="/ref#sClass"></a>' + '<a href="#">' + j + '</a></li>')
					.insertBefore($('.next,.last', an[i])[0])
					.bind('click', function(e) {
						e.preventDefault();
						oSettings._iDisplayStart = (parseInt($('a', this).text(), 10) - 1) * oPaging.iLength;
						fnDraw(oSettings);
					});
				}

				// Add / remove disabled classes from the static elements
				if (oPaging.iPage === 0) {
					$('li:first', an[i]).addClass('disabled');
					$('li.prev').addClass('disabled');
				} else {
					$('li:first', an[i]).removeClass('disabled');
					$('li.prev').removeClass('disabled');
				}

				if (oPaging.iPage === oPaging.iTotalPages - 1 || oPaging.iTotalPages === 0) {
					$('li:last', an[i]).addClass('disabled');
					$('li.next').addClass('disabled');
				} else {
					$('li:last', an[i]).removeClass('disabled');
					$('li.next').removeClass('disabled');
				}
			}
		}
	}
});

/* Função que monta a tabela de Andamento */
function andamentoTabela(nomeTabela){
	oTable = $('#andamentoTable').dataTable( {
		"bStateSave": false,
		"bJQueryUI": true,
		"bProcessing": true,
		"sAjaxSource": nomeTabela, //Arquivo que carrega
		"sDom": "lftipr<'clearb exportar'T>",
		"sPaginationType": "bootstrap",
		"aLengthMenu": [[10, 50, 100, -1], [10, 50, 100, 'Todos']],
		"oLanguage":  aoLanguage,
		"oTableTools": {
			"sSwfPath": sSwfPath,
			"aButtons": [
			{"sExtends": "xls","sButtonText": "XLS"},
			{"sExtends": "pdf", "sButtonText": "PDF"}]},
			"aoColumns": aoColumns,
			"fnDrawCallback": function() {
				funcaoLabel(); maisInfoAndamento();},
				"fnInitComplete": function() {}
			}).yadcf([
		//Filtro das colunas
		{column_number: 2},
		{column_number: 4}]);

		};

		/* Função de monta a tabela de Finalizadas */
		function finalizadaTabela(nomeTabela){
			oTableB = $('#finalizadaTable').dataTable( {
				"bStateSave": false,
				"bJQueryUI": true,
				"bProcessing": true,
				"bAutoWidth": false,
		"sAjaxSource": nomeTabela, //Arquivo que carrega

		//Ajusta a ordem dos componentes.
		"sDom": "lftipr<'clearb exportar'T>",

		//Páginação bootstrap
		"sPaginationType": "bootstrap",

		//Quantidade de itens do select
		"aLengthMenu": [[10, 50, 100, -1], [10, 50, 100, 'Todos']],

		//Tradução do componente
		"oLanguage": aoLanguage,

		//Componentes para exportar arquivo
		"oTableTools": {
			"sSwfPath": sSwfPath,
			"aButtons": [
			{"sExtends": "xls","sButtonText": "XLS"},
			{"sExtends": "pdf", "sButtonText": "PDF"}
			]},

		//Ajustando as colunas para o filtro
		"aoColumns": aoColumnsFinalizada,

		"fnDrawCallback": function() {funcaoLabel(); maisInfoFinal();},
		"fnInitComplete": function() {funcaoLabel();}
	}).yadcf([
		//Filtro das colunas
		{column_number: 2},
		{column_number: 4}]);

}

/*Função dos componente de Ponto de Medição  */
var compTabela = function(caminhoAjax){
	oTableA = $('#tabPontoMed').dataTable( {
		"bStateSave": true,
		"bJQueryUI": true,
		"bProcessing": false,
		"bAutoWidth": true,
		"bLengthChange": false,
		"sAjaxSource": caminhoAjax, //Arquivo que carrega
		"bFilter": false,
		"bInfo": false,
		"aoColumnDefs": [{
			"bSortable": false, "aTargets": [ 3 ]
		}],

		"oLanguage": {
			"sProcessing":   "Processando...",
			"sLengthMenu":   "Quantidade de resultados: _MENU_",
			"sZeroRecords":  "Não foram encontrados resultados",
			"sInfo":         "Mostrando de _START_ até _END_ de _TOTAL_ registros",
			"sInfoEmpty":    "Mostrando de 0 até 0 de 0 registros",
			"sInfoFiltered": "(filtrado de _MAX_ registros no total)",
			"sInfoPostFix":  "",
			"sSearch":       "",
			"sUrl":          "",
			"oPaginate": {
				"sFirst":    "Primeiro",
				"sPrevious": "Anterior",
				"sNext":     "Seguinte",
				"sLast":     "Último"
				}
			},

		//Função de expandir
		"fnInitComplete": function(oSettings, json) {

			$('#tabPontoMed .btn-primary').click(function () {

				var nTr = $(this).parents('tr')[0];
				var tipoExt = $(this).parents('tr').find('.tipo').text();

				if ( oTableA.fnIsOpen(nTr) ) {
					$(this).removeClass('btn-default').addClass('btn-primary').attr('title', 'Detalhar').find('.glyphicon').removeClass('glyphicon-zoom-out').addClass('glyphicon-zoom-in');

					oTableA.fnClose( nTr );

				} else {
					$(this).removeClass('btn-primary').addClass('btn-default').attr('title', 'Recolher').find('.glyphicon').removeClass('glyphicon-zoom-in').addClass('glyphicon-zoom-out');
					oTableA.fnOpen( nTr, PontoMedicao( nTr ), 'details' );
				}
			});
		}
		//Final do Data Table
	});
};

/*Função dos componente de Ponto de Medição  */
function unidadeGeradoraTabela(caminhoAjax){
	oTable = $('#tabUnidadeGeradora').dataTable( {
		"bStateSave": true,
		"bJQueryUI": true,
		"bProcessing": false,
		"bAutoWidth": true,
		"bLengthChange": false,
		"sAjaxSource": caminhoAjax, //Arquivo que carrega
		"bFilter": false,
		"bInfo": false,

		"oLanguage": {
			"sProcessing":   "Processando...",
			"sLengthMenu":   "Quantidade de resultados: _MENU_",
			"sZeroRecords":  "Não foram encontrados resultados",
			"sInfo":         "Mostrando de _START_ até _END_ de _TOTAL_ registros",
			"sInfoEmpty":    "Mostrando de 0 até 0 de 0 registros",
			"sInfoFiltered": "(filtrado de _MAX_ registros no total)",
			"sInfoPostFix":  "",
			"sSearch":       "",
			"sUrl":          "",
			"oPaginate": {
				"sFirst":    "Primeiro",
				"sPrevious": "Anterior",
				"sNext":     "Seguinte",
				"sLast":     "Último"},

			},

		//Função de expandir
		"fnInitComplete": function(oSettings, json) {

			$('.btn-delete').on('click', function(event) {
				event.preventDefault();
				_this = $(this);
				$(this).parents('tr').remove()
				$('.removed').fadeIn();
			});

			$('#tabUnidadeGeradora .btn-expandir').click(function () {
				var nTr = $(this).parents('tr')[0];
				var tipoExt = $(this).parents('tr').find('.tipo').text();

				if ( oTable.fnIsOpen(nTr) ) {
					if ( $(this).parents('td').find('.btn-editar-unidade').hasClass('btn-default') ) {
						$('#tabUnidadeGeradora').find('table .edit').hide();
						$('#tabUnidadeGeradora').find('table .data').show();
						$('#tabUnidadeGeradora').find('.btn-gravar').hide();
						$(this).parents('td').find('.btn-editar-unidade').removeClass('btn-default').addClass('btn-success').attr('title', 'Editar');
						$(this).removeClass('btn-primary').addClass('btn-default').attr('title', 'Recolher').find('.glyphicon').removeClass('glyphicon-zoom-in').addClass('glyphicon-zoom-out');
					} else {
						$(this).removeClass('btn-default').addClass('btn-primary').attr('title', 'Detalhar').find('.glyphicon').removeClass('glyphicon-zoom-out').addClass('glyphicon-zoom-in');
						oTable.fnClose( nTr );
					}
				} else {
					$(this).removeClass('btn-primary').addClass('btn-default').attr('title', 'Recolher').find('.glyphicon').removeClass('glyphicon-zoom-in').addClass('glyphicon-zoom-out');
					oTable.fnOpen( nTr, UnidadeGeradora( nTr ), 'details' );
				}
			});

			$('#tabUnidadeGeradora .btn-editar-unidade').click(function () {
				var nTr = $(this).parents('tr')[0];
				var tipoExt = $(this).parents('tr').find('.tipo').text();

				if ( oTable.fnIsOpen(nTr) ) {
					if ( $(this).parents('td').find('.btn-expandir').hasClass('btn-default') ) {
						$('#tabUnidadeGeradora').find('table .edit').show();
						$('#tabUnidadeGeradora').find('table .data').hide();
						$('#tabUnidadeGeradora').find('.btn-gravar').show();
						$(this).parents('td').find('.btn-expandir').removeClass('btn-default').addClass('btn-primary').attr('title', 'Editar');
						$(this).removeClass('btn-success').addClass('btn-default').attr('title', 'Recolher');
					} else {
						$(this).removeClass('btn-default').addClass('btn-success').attr('title', 'Editar');
						oTable.fnClose( nTr );
					}

				} else {
					$(this).removeClass('btn-success').addClass('btn-default').attr('title', 'Recolher');

					oTable.fnOpen( nTr, UnidadeGeradora( nTr ), 'details' );
					editUnidadesGeradoras();
					$('.dataPickSingle').daterangepicker({
						singleDatePicker: true,
						startDate: moment(),
						format: 'DD/MM/YYYY',
						setStartDate: moment(),
					});
				}
			});

		},
		//Final do Data Table

	});
};

/*Funçôes dos componente de Agentes  */
function agenteTabela(caminhoAjax,nameTable, aoColumns){
	oTable = $(nameTable).dataTable( {
		"bStateSave": true,
		"bJQueryUI": true,
		"bProcessing": false,
		"bAutoWidth": true,
		"bLengthChange": false,
		"sAjaxSource": caminhoAjax, //Arquivo que carrega
		"bFilter": false,
		"bInfo": false,
		"aoColumns" : aoColumns,

		"oLanguage": aoLanguage,
	});

};

function agenteTabelaEstatico(caminhoAjax,nameTable){
	oTable = $(nameTable).dataTable( {
		"bStateSave": true,
		"bJQueryUI": true,
		"bProcessing": false,
		"bAutoWidth": true,
		"bLengthChange": false,
		"sAjaxSource": caminhoAjax, //Arquivo que carrega
		"bFilter": false,
		"bInfo": false,

		"oLanguage": aoLanguage,
	});
};

function concessionariaTabelaEstatico(caminhoAjax,nameTable){
	oTable = $(nameTable).dataTable( {
		"bStateSave": true,
		"bJQueryUI": true,
		"bProcessing": false,
		"bAutoWidth": true,
		"bLengthChange": false,
		"sAjaxSource": caminhoAjax, //Arquivo que carrega
		"bFilter": false,
		"bInfo": false,

		"oLanguage": aoLanguage,

		"fnInitComplete": function() {
			//Componente Agente
			$('#resultadoAgentes table input:radio').on('change',function(){
				var resultAgente = $(this).closest('td').next().next().text();
				$('[name="inputAgenteConcessionario"]').val(resultAgente).attr("disabled",false);
				$('#pesquisarConcessionaria').collapse('toggle');
				$('a[href="#pesquisarConcessionaria"]').addClass('collapsed');
			});
		}

	});
};

function influenciadaTabelaEstatico(caminhoAjax,nameTable){
	oTable = $(nameTable).dataTable( {
		"bStateSave": true,
		"bJQueryUI": true,
		"bProcessing": false,
		"bAutoWidth": true,
		"bLengthChange": false,
		"sAjaxSource": caminhoAjax, //Arquivo que carrega
		"bFilter": false,
		"bInfo": false,

		"oLanguage": aoLanguage,

		"fnInitComplete": function() {
			//Componente Agente
			$('#resultadoInfluenciadas table input:radio').on('change',function(){
				var resultAgente = $(this).closest('td').next().next().text();
				$('[name="inputConcessionarioIn"]').val(resultAgente).attr("disabled",false);
				$('#pesquisarInfluenciada').collapse('toggle');
				$('a[href="#pesquisarInfluenciada"]').addClass('collapsed');
			});
		}

	});
};
/*FIM Funçôes dos componente de Agentes  */

/* Tabelas de resultados de Ponto de Medição */
function resultTabela(caminhoAjax, tabela){
	oTable = $(tabela).dataTable( {
		"bStateSave": true,
		"bJQueryUI": true,
		"bProcessing": false,
		"bAutoWidth": true,
		"bLengthChange": false,
		"sAjaxSource": caminhoAjax, //Arquivo que carrega
		"bFilter": false,
		"bInfo": false,
		"aoColumns": aoColumnsResult,
		"oLanguage": aoLanguage,
		"aoColumnDefs": [{
			"bSortable": false, "aTargets": [ 2 ]
		}],

		//Função de expandir
		"fnInitComplete": function(oSettings, json) {

			$('.btn-delete').on('click', function(event) {
				event.preventDefault();
				$(this).parents('tr').remove();
				$('.removed').fadeIn();
			});

			$('#tabPontoMedResult .btn-primary').click(function () {

				var nTr = $(this).parents('tr')[0];
				var tipoExt = $(this).parents('tr').find('.tipo').text();

				if ( oTable.fnIsOpen(nTr) ) {
					$(this).removeClass('btn-default').addClass('btn-primary').attr('title', 'Detalhar').find('.glyphicon').removeClass('glyphicon-zoom-out').addClass('glyphicon-zoom-in');
					oTable.fnClose( nTr );
				} else {
					$(this).removeClass('btn-primary').addClass('btn-default').attr('title', 'Recolher').find('.glyphicon').removeClass('glyphicon-zoom-in').addClass('glyphicon-zoom-out');

					oTable.fnOpen( nTr, PontoMedicao( nTr ), 'details' );
				}
			});
		}
	});
}

function resultTabelaEstatico(caminhoAjax, tabela){
	oTableB = $(tabela).dataTable( {
		"bStateSave": true,
		"bJQueryUI": true,
		"bProcessing": false,
		"bAutoWidth": true,
		"bLengthChange": false,
		"sAjaxSource": caminhoAjax, //Arquivo que carrega
		"bFilter": false,
		"bInfo": false,

		"oLanguage": aoLanguage
	});

}
/*FIM Tabelas de resultados de Ponto de Medição */

/* Tabela de Resuldatos de Agentes Consorciados */
function consorcioTabela(caminhoAjax, tabela){
	oTableD = $(tabela).dataTable( {
		"bStateSave": true,
		"bJQueryUI": true,
		"bProcessing": false,
		"bAutoWidth": true,
		"bLengthChange": false,
		"sAjaxSource": caminhoAjax, //Arquivo que carrega
		"bFilter": false,
		"bInfo": false,
		"aoColumns": aoColumnsConsorciado,

		"oLanguage": aoLanguage
	});
}

/* Tabela de Anexos e Anexos Unidades Geradoras */
function anexosTabela(caminhoAjax, tabela, aoColumns){
	oTableD = $(tabela).dataTable( {
		"bStateSave": true,
		"bJQueryUI": true,
		"bProcessing": false,
		"bAutoWidth": true,
		"bLengthChange": false,
		"sAjaxSource": caminhoAjax, //Arquivo que carrega
		"bFilter": false,
		"bInfo": false,

		"aoColumns": aoColumns,

		"oLanguage": aoLanguage
	});
}

/* Tabela de Anexos e Anexos Atrelados a SMA */
function anexosTabelaUnidadeGeradora(caminhoAjax, tabela, aoColumns){
	oTableD = $(tabela).dataTable( {
		"bStateSave": true,
		"bJQueryUI": true,
		"bProcessing": false,
		"bAutoWidth": true,
		"bLengthChange": false,
		"sAjaxSource": caminhoAjax, //Arquivo que carrega
		"bFilter": false,
		"bInfo": false,

		"aoColumns": aoColumns,
		"oLanguage": aoLanguage
	});
}

/* Tabela de Anexos e Anexos Atrelados a SMA */
function anexosTabelaAtreladosSMA(caminhoAjax, tabela, aoColumns){
	oTableD = $(tabela).dataTable( {
		"bStateSave": true,
		"bJQueryUI": true,
		"bProcessing": false,
		"bAutoWidth": true,
		"bLengthChange": false,
		"sAjaxSource": caminhoAjax, //Arquivo que carrega
		"bFilter": false,
		"bInfo": false,

		"aoColumns": aoColumns,

		"oLanguage": aoLanguage
	});
}

/* Combobox */
(function( $ ) {
	$.widget( "custom.combobox", {
		_create: function() {
			this.wrapper = $( "<span>" )
			.addClass( "custom-combobox" )
			.insertAfter( this.element );

			this.element.hide();
			this._createAutocomplete();
			this._createShowAllButton();
		},

		_createAutocomplete: function() {
			var selected = this.element.children( ":selected" ),
			value = selected.val() ? selected.text() : "";

			this.input = $( "<input>" )
			.appendTo( this.wrapper )
			.val( value )
			.attr( "title", "" )
			.addClass( "custom-combobox-input ui-widget ui-widget-content ui-state-default ui-corner-left form-control" )
			.autocomplete({
				delay: 0,
				minLength: 0,
				source: $.proxy( this, "_source" )
			})
			.tooltip({
				tooltipClass: "ui-state-highlight"
			});

			this._on( this.input, {
				autocompleteselect: function( event, ui ) {
					ui.item.option.selected = true;
					this._trigger( "select", event, {
						item: ui.item.option
					});
				},

				autocompletechange: "_removeIfInvalid"
			});
		},

		_createShowAllButton: function() {
			var input = this.input,
			wasOpen = false;

			$( "<a>" )
			.attr( "tabIndex", -1 )
			.attr( "title", "Mostrar todos os itens" )
			.tooltip()
			.appendTo( this.wrapper )
			.button({
				icons: {
					primary: "ui-icon-triangle-1-s"
				},
				text: false
			})
			.removeClass( "ui-corner-all" )
			.addClass( "custom-combobox-toggle ui-corner-right" )
			.mousedown(function() {
				wasOpen = input.autocomplete( "widget" ).is( ":visible" );
			})
			.click(function() {
				input.focus();

				// Close if already visible
				if ( wasOpen ) {
					return;
				}

				// Pass empty string as value to search for, displaying all results
				input.autocomplete( "Buscar", "" );
			});
		},

		_source: function( request, response ) {
			var matcher = new RegExp( $.ui.autocomplete.escapeRegex(request.term), "i" );
			response( this.element.children( "option" ).map(function() {
				var text = $( this ).text();
				if ( this.value && ( !request.term || matcher.test(text) ) )
					return {
						label: text,
						value: text,
						option: this
					};
				}) );
		},

		_removeIfInvalid: function( event, ui ) {

		// Selected an item, nothing to do
		if ( ui.item ) {
			return;
		}

		// Search for a match (case-insensitive)
		var value = this.input.val(),
		valueLowerCase = value.toLowerCase(),
		valid = false;
		this.element.children( "option" ).each(function() {
			if ( $( this ).text().toLowerCase() === valueLowerCase ) {
				this.selected = valid = true;
				return false;
			}
		});

		// Found a match, nothing to do
		if ( valid ) {
			return;
		}

		// Remove invalid value
		this.input
		.val( "" )
		.attr( "termo", value + " não encontrado" )
		.tooltip( "open" );
		this.element.val( "" );
		this._delay(function() {
			this.input.tooltip( "close" ).attr( "title", "" );
		}, 2500 );
		this.input.data( "ui-autocomplete" ).term = "";
	},

	_destroy: function() {
		this.wrapper.remove();
		this.element.show();
	}
});
})( jQuery );

//Internet Explorer Place Holder
function iePlaceHolder(){
	// Placeholder fix for IE
	$('.lt-ie10 [placeholder]').focus(function() {
		var i = $(this);
		if(i.val() == i.attr('placeholder')) {
			i.val('').removeClass('placeholder');
			if(i.hasClass('password')) {
				i.removeClass('password');
				this.type='password';
			}
		}
	}).blur(function() {
		var i = $(this);
		if(i.val() == '' || i.val() == i.attr('placeholder')) {
			if(this.type=='password') {
				i.addClass('password');
				this.type='text';
			}
			i.addClass('placeholder').val(i.attr('placeholder'));
		}
	}).blur().parents('form').submit(function() {
	//if($(this).validationEngine('validate')) { // If using validationEngine
		$(this).find('[placeholder]').each(function() {
			var i = $(this);
			if(i.val() == i.attr('placeholder'))
				i.val('');
			i.removeClass('placeholder');

		})
	//}
	});
}

//Input file customizado
function inputCustom(){
	$(':file').filestyle({buttonText: "Anexar Arquivo"});
}

//Função para aparecer os icones de ajudar "ToolTip"
function fadeInIcons(){
	$('.page-header.row strong').click(function() {
		$('.form-horizontal .ajudaTit').toggle('fast');
	});
}

//Função para os alerts dos formulários
function alertsForms(){
	$(".encaminhar").click(function(){
		$(".alert.alert-danger").alert().fadeIn('slow');
		$('body, html').animate({scrollTop:0},600);
	});

	$(".gravar").click(function(){
		$(".alert.alert-success").alert().fadeIn('slow');
		$('body, html').animate({scrollTop:0},600);
	});
}

//Função para voltar ao topo da página ao clicar nos btns anterior e seguinte
function backTopDataTables(){
	$(".pagination , .btn-recolher, .validar-solicitacao tr td .aprovar-todos").click(function(){
		$('body , html').animate({scrollTop:0},600);
	});
}

//Função para deixar com cor verde as tabelas de validação/aprovação ao clicar em Aprovar Todos
function backgroundTableAprovarTodos(){
	$(".validar-solicitacao tr td .aprovar-todos").click(function(){
		$(".validar-solicitacao").css("background-color" , "#E1EED9");
		$(".validar-solicitacao tr:last-child td, .validar-solicitacao tr td .tables-internas tr td").css("background-color" , "#ffffff");
	});
}

function editUnidadesGeradoras(){

	$('#tabUnidadeGeradora').find('table .edit').show();
	$('#tabUnidadeGeradora').find('table .data').hide();
	$('#tabUnidadeGeradora').find('.btn-gravar').show();
	//$('#tabUnidadeGeradora').find('.link-cancelar').show();

	$('#tabUnidadeGeradora .link-cancelar').on('click', function(event) {
		$('#tabUnidadeGeradora').find('table .edit').hide();
		$('#tabUnidadeGeradora').find('table .data').show();
		$('#tabUnidadeGeradora').find('.btn-gravar').hide();
		//$('#tabUnidadeGeradora').find('.link-cancelar').hide();
	});

	$('#tabUnidadeGeradora .btn-gravar').on('click', function(event) {
		$('.included').fadeIn();
	});
}